<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>mixin</title>
  <script src="/vue.js"></script>
</head>
<body>
  <div id="root">
    <comp1></comp1>
    <comp2></comp2>
  </div>
  <script>
    // Vue.mixin({
    //   data() {
    //     return {
    //       y: 10,
    //       x: 300
    //     }
    //   },
    //   methods: {
    //     print(info) {
    //       console.log(info)
    //     }
    //   },
    //   computed: {
    //     doubley() {
    //       console.log('doubley')
    //       return this.y + this.y
    //     },
    //     doublex() {
    //       return this.x + this.x
    //     }
    //   },
    //   mounted() {
    //     console.log('mixin mouted.')
    //   },
    // })

    const mixin = {
      data() {
        return {
          x: 10000
        }
      }
    }

    Vue.component('comp1', {
      mixins: [mixin],
      data() {
        return {
          y: 1000
        }
      },
      computed: {
        doubley() {
          return this.y + this.y
        }
      },
      template: `
        <div @click="print('hello')">
          comp1 {{y}} {{doubley}} {{x}}
          <button @click.stop="print">click</button>
        </div>
      `,
      methods: {
        print() {
          console.log(100)
        }
      },
      mounted() {
        console.log('comp1 mounted.')
      },
    })

    Vue.component('comp2', {
      template: `
        <div @click="print('world')">comp2</div>
      `
    })

    var vm = new Vue({
      el: '#root',
      
    })
  </script>
</body>
</html>